﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Com.LongER.Framework.Utils;
using Com.LongER.UI;
using Com.LongER.Business.ZDH001;
using Com.LongER.Framework.Utils.LogUtils;

public partial class ZDH001 : ABasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //
        if (!this.Page.IsPostBack)
        {
            Label lblPageId = (Label)Master.FindControl("lblPageId");
            lblPageId.Text = "ZDH001";

            Label lblPageName = (Label)Master.FindControl("lblPageName");
            lblPageName.Text = "车辆一览查询画面";

            //清空画面中的输入框
            #region
            proc清空_Init("0");

            #endregion
            //焦点位于用户ID输入框中
            this.txt车牌号.Focus();

        }
        //autocomplete
        //this.txt车牌号.Text = this.hid车牌号.Value;
        this.txt所属区分.Text = this.hid所属区分.Value;
        this.txt运输形态.Text = this.hid运输形态.Value;
        this.txt所用车型.Text = this.hid所用车型.Value;
        this.txt车辆运营状态.Text = this.hid车辆运营状态.Value;
        this.txt车辆运输状态.Text = this.hid车辆运输状态.Value;
        this.txt省市.Text = this.hid省市.Value;
        //this.txt地方.Text = this.hid地方.Value;

    }

    protected void btn执行_Click(object sender, EventArgs e)
    {
        Dictionary<string, string> dic = new Dictionary<string, string>();
        dic.Add("CHEPAI_NUM", this.txt车牌号.Text.ToString());
        dic.Add("SHO", this.txt所属区分CD.Text.ToString());
        dic.Add("YUNSHU_XINGTAI", this.txt运输形态CD.Text.ToString());

        //
        if (this.hidPageNo.Value == string.Empty) this.hidPageNo.Value = "1";
        dic.Add("PAGE_NO", this.hidPageNo.Value);

        CZDH001 instance = new CZDH001();

        ZDH001DS.M_CHEDataTable dt = instance.GetCheList(dic);

        #region
        //总件数清空
        this.txt总件数.Text = string.Empty;
        //标题行以外全部移除
        for (int i = this.tblList.Rows.Count - 1; i >= 1; i--)
        {
            this.tblList.Rows.RemoveAt(i);
        }

        Label lblMsgCD = (Label)Master.FindControl("lblMsgCD");
        lblMsgCD.Text = "  ";

        Label lblMsg = (Label)Master.FindControl("lblMsg");
        lblMsg.Text = "  ";
        #endregion

        #region
        //查询结果不为空时
        if (dt.Count > 0)
        {
            this.txt总件数.Text = dt.Count.ToString();

            //查询成功
            this.SetMessage("GTH002", "IGTH002000", MSG_LEVEL.Info);
        }
        //查询结果为空时
        else
        {
            //查询失败
            this.SetMessage("GTH002", "IGTH002001", MSG_LEVEL.Error); 
            return;
        }

        int rowid = 0;
        //
        foreach (var dr in dt)
        {
            //创建新行
            TableRow row = new TableRow();
            if (rowid % 2 == 0) { row.CssClass = "odd"; } else { row.CssClass = "even"; }

            //选择
            TableCell cell = GetTableCell(width: 30, rowspan: 1);
            //
            RadioButton rb = new RadioButton();
            rb.ID = "rb" + rowid;
            rb.GroupName = "rad";
            if (rowid == 0) rb.Checked = true;

            cell.Controls.Add(rb);
            row.Cells.Add(cell);//插入单元格

            //车牌号
            cell = GetTableCell(width: 70);
            cell.Text = dr.CHEPAI_NUM;
            row.Cells.Add(cell);

            //所属区分
            cell = GetTableCell(width: 40);
            cell.Text = dr.SHO_HANZI;
            row.Cells.Add(cell);

            //运输形态
            cell = GetTableCell(width: 60);
            cell.Text = dr.YSXT_HANZI;
            row.Cells.Add(cell);

            //运输性质
            cell = GetTableCell(width: 60);
            cell.Text = dr.YSXZ_HANZI;
            row.Cells.Add(cell);

            //车辆运营状态
            cell = GetTableCell(width: 50);
            cell.Text = dr.YYZT_HANZI;
            row.Cells.Add(cell);

            //车长
            cell = GetTableCell(width: 45);
            cell.Text = dr.CHE_CHANG;
            row.Cells.Add(cell);

            //车宽
            cell = GetTableCell(width: 45);
            cell.Text = dr.CHE_KUAN;
            row.Cells.Add(cell);

            //可承载重量
            cell = GetTableCell(width: 80);
            cell.Text = dr.ZHUANGZAI_ZHONGLIANG;
            row.Cells.Add(cell);

            //使用年数
            cell = GetTableCell(width: 90);
            cell.Text = dr.USED_YEARS;
            row.Cells.Add(cell);

            //年检有效日期
            cell = GetTableCell(width: 120);
            cell.Text = dr.CHK_YOUXIAO_DATE;
            row.Cells.Add(cell);

            //车主
            cell = GetTableCell(width: 80);
            cell.Text = dr.KEHU_HANZI;
            row.Cells.Add(cell);

            //联系电话1
            cell = GetTableCell(width: 120);
            cell.Text = dr.KEHU_TELNUM1;
            row.Cells.Add(cell);

            //联系电话2
            cell = GetTableCell(width: 120);
            cell.Text = dr.KEHU_TELNUM2;
            row.Cells.Add(cell);

            //主驾驶员
            cell = GetTableCell(width: 80);
            cell.Text = dr.ZHUJIA_HANZI;
            row.Cells.Add(cell);

            //主驾联系电话
            cell = GetTableCell(width: 120);
            cell.Text = dr.ZHUJIA_MOBIL1;
            row.Cells.Add(cell);

            //副驾驶员
            cell = GetTableCell(width: 80);
            cell.Text = dr.FUJIA_HANZI;
            row.Cells.Add(cell);

            //副驾联系电话
            cell = GetTableCell(width: 120);
            cell.Text = dr.FUJIA_MOBIL1;
            row.Cells.Add(cell);

            
            this.tblList.Rows.Add(row);
            rowid++;
        }

        #endregion
    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="width"></param>
    /// <param name="rowspan"></param>
    /// <returns></returns>
    private TableCell GetTableCell(int width = -1, int rowspan = 1, int colspan = 1)
    {
        //创建单元格对象
        TableCell cell = new TableCell();
        if (width != -1) cell.Width = width;
        if (rowspan > 1) cell.RowSpan = rowspan;
        if (colspan > 1) cell.ColumnSpan = colspan;
        return cell;
    }

    protected void proc清空_Init(string str处理区分)
    {
        Label lblMsgCD = (Label)Master.FindControl("lblMsgCD");
        Label lblMsg = (Label)Master.FindControl("lblMsg");
        lblMsgCD.Text = "";
        lblMsg.Text = "";

            //控件的Enabled进行控制
            #region
            this.txt车牌号.Enabled = true;
            this.txt所属区分CD.Enabled = true;
            this.txt运输形态CD.Enabled = true;
            this.txt所用车型CD.Enabled = true;
            this.txt车长.Enabled = true;
            this.txt车宽.Enabled = true;
            this.txt可承载重量.Enabled = true;
            this.txt使用月数.Enabled = true;
            this.txt年检有效日期年.Enabled = true;
            this.txt年检有效日期月.Enabled = true;
            this.txt车主CD.Enabled = true;
            this.txt车主.Enabled = true;
            this.txt车主联系电话1.Enabled = true;
            this.txt车主联系电话2.Enabled = true;
            this.txt车辆运营状态CD.Enabled = true;
            this.txt车辆运输状态CD.Enabled = true;
            this.txt车辆装载率.Enabled = true;
            this.txt省市CD.Enabled = true;

            this.txt车牌号.Text = string.Empty;
            this.txt所属区分CD.Text = string.Empty;
            this.txt所属区分.Text = string.Empty;
            this.txt运输形态CD.Text = string.Empty;
            this.txt运输形态.Text = string.Empty;
            this.txt所用车型CD.Text = string.Empty;
            this.txt所用车型.Text = string.Empty;
            this.txt车长.Text = string.Empty;
            this.txt车宽.Text = string.Empty;
            this.txt可承载重量.Text = string.Empty;
            this.txt使用月数.Text = string.Empty;
            this.txt年检有效日期年.Text = string.Empty;
            this.txt年检有效日期月.Text = string.Empty;
            this.txt车主CD.Text = string.Empty;
            this.txt车主.Text = string.Empty;
            this.txt车主联系电话1.Text = string.Empty;
            this.txt车主联系电话2.Text = string.Empty;
            this.txt车辆运营状态CD.Text = string.Empty;
            this.txt车辆运营状态.Text = string.Empty;
            this.txt车辆运输状态CD.Text = string.Empty;
            this.txt车辆运输状态.Text = string.Empty;
            this.txt车辆装载率.Text = string.Empty;
            this.txt省市CD.Text = string.Empty;
            this.txt省市.Text = string.Empty;

            #endregion

            //总件数
            this.txt总件数.Text = string.Empty;

            //数据表清空
            for (int i = this.tblList.Rows.Count - 1; i >= 1; i--)
            {
                this.tblList.Rows.RemoveAt(i);
            }

    }

    protected void btn清除_Click(object sender, EventArgs e)
    {
        //初期化处理
        #region
        //查询时，各个控件的属性进行控制
        proc清空_Init("1");
        #endregion
    }

    protected void btn主菜单_Click(object sender, EventArgs e)
    {
        Response.Redirect("/LongER/ZAH003.aspx");
    }
}